﻿function openResult(evt, Result) {
    var i, x, tablinks;
    x = document.getElementsByClassName("class-student-results");
    for (i = 0; i < x.length; i++) {
        x[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablink");
    for (i = 0; i < x.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" w3-teal", "");
    }
    document.getElementById(Result).style.display = "block";
    evt.currentTarget.className += " w3-teal";
}

function close_student_detail() {
    $("#class-report").css("display", "block");
    $("#student_detail_area").css("display", "none");
    $(".studentlinks").removeClass("w3-leftbar w3-border-teal");
}
$(document).ready(function () {
    $("#ddl_class").on("change", function () {
        document.getElementById("student_list").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
        var id = document.getElementById("ddl_class").value;
        var studentlinks = document.getElementsByClassName("studentlinks");
        document.getElementById("student_detail_area").style.display = 'none';
        if (id != -1) {
            $("#class-list-option-btn").removeClass("w3-hide");
            $("#class-report").css("display", "block");
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    $(document).ready(function () {
                        document.getElementById("student_list").innerHTML = xhttp.responseText;
                        $(".studentlinks").click(function () {
                            $("#class-report").css("display", "none");
                            document.getElementById("student_detail_area").style.display = 'block';
                            document.getElementById("student_detail_area").innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';
                            var id = this.getElementsByClassName("student_id")[0].innerHTML;
                            
                            for (var j = 0; j < studentlinks.length; j++) {
                                studentlinks[j].className = studentlinks[j].className.replace(" w3-leftbar w3-border-teal", "");
                            }
                            $(this).addClass(" w3-leftbar w3-border-teal");
                            var xhttp;
                            xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                                if (xhttp.readyState == 4 && xhttp.status == 200) {
                                    $(document).ready(function () {
                                        document.getElementById("student_detail_area").innerHTML = xhttp.responseText;
                                        $(".btn_detail_date").on("click", function () {
                                            var from = document.getElementById("from").value;
                                            var to = document.getElementById("to").value;

                                            var id = document.getElementById("student_id").innerHTML;
                                            if (from == "") {
                                                alert("Giá trị Từ Ngày không đúng định dạng!");
                                            }
                                            else {
                                                if (to == "") {
                                                    alert("Giá trị Đến Ngày không đúng định dạng!");
                                                }
                                                else {
                                                    var xhttp1;
                                                    xhttp1 = new XMLHttpRequest();
                                                    xhttp1.onreadystatechange = function () {
                                                        if (xhttp1.readyState == 4 && xhttp1.status == 200) {
                                                            $(document).ready(function () {
                                                                document.getElementById('chuyencan').innerHTML = xhttp1.responseText;
                                                            });
                                                        }
                                                    };

                                                    xhttp1.open("GET", "../ajax/asp/class/get_hard_rate.aspx?id=" + id + "&from=" + from + "&to=" + to, true);
                                                    xhttp1.send();

                                                    var xhttp2;
                                                    xhttp2 = new XMLHttpRequest();
                                                    xhttp2.onreadystatechange = function () {
                                                        if (xhttp2.readyState == 4 && xhttp2.status == 200) {
                                                            $(document).ready(function () {
                                                                document.getElementById('kiemtra').innerHTML = xhttp2.responseText;
                                                            });
                                                        }
                                                    };
                                                    xhttp2.open("GET", "../ajax/asp/class/get_test_by_time.aspx?id=" + id + "&from=" + from + "&to=" + to, true);
                                                    xhttp2.send();
                                                }
                                            }

                                        });
                                        var randomColorFactor = function () {
                                            return Math.round(Math.random() * 255);
                                        };
                                        var randomColor = function (opacity) {
                                            return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.8') + ')';
                                        };
                                        var skill_label = document.getElementsByClassName("skill_label_child");
                                        var data_child = document.getElementsByClassName("skill_data_child");
                                        var data_text = document.getElementById("skill_text").innerHTML;
                                        var chart_labels = [];
                                        var chart_data = [];
                                        for (var i = 0; i < skill_label.length; i++) {
                                            chart_labels.push(skill_label[i].innerHTML);
                                            chart_data.push(data_child[i].innerHTML);
                                        }
                                        var config1 = {
                                            type: 'radar',
                                            data: {
                                                labels: chart_labels,
                                                datasets: [{
                                                    label: "Tổng kỹ năng",
                                                    data: chart_data,
                                                }]
                                            },
                                            options: {
                                                responsive: true,
                                                title: {
                                                    display: true,
                                                    text: data_text
                                                },
                                                tooltips: {
                                                    mode: 'label',
                                                },
                                                hover: {
                                                    mode: 'label'
                                                },
                                            }
                                        };
                                        $.each(config1.data.datasets, function (i, dataset) {
                                            var color = randomColor(0);
                                            dataset.borderColor = color;
                                            dataset.backgroundColor = color;
                                            dataset.pointBorderColor = color;
                                            dataset.pointBackgroundColor = color;
                                            dataset.pointBorderWidth = 1;
                                        });
                                        var ctx = document.getElementById("student_skill").getContext("2d");
                                        window.myLine = new Chart(ctx, config1);
                                    });
                                }
                            };
                            xhttp.open("GET", "../ajax/asp/class/student_detail.aspx?id=" + id, true);
                            xhttp.send();
                        });
                    });
                }
            };
            xhttp.open("GET", "../ajax/asp/class/show_member.aspx?id=" + id, true);
            xhttp.send();
                var xhttp1;
                xhttp1 = new XMLHttpRequest();
                xhttp1.onreadystatechange = function () {
                    if (xhttp1.readyState == 4 && xhttp1.status == 200) {
                        document.getElementsByClassName("class-point-report")[0].innerHTML = xhttp1.responseText;
                        $("#ddl_report_semester").on("change", function () {
                            var semester = document.getElementById("ddl_report_semester").value;
                            var xhttp;
                            xhttp = new XMLHttpRequest();
                            xhttp.onreadystatechange = function () {
                                if (xhttp.readyState == 4 && xhttp.status == 200) {
                                    document.getElementById("ddl_report_group").innerHTML = xhttp.responseText;
                                }
                            };
                            xhttp.open("GET", "../ajax/asp/class/get_exam_group.aspx?id=" + semester, true);
                            xhttp.send();
                        });
                    }
                };
                xhttp1.open("GET", "../ajax/asp/class/report_score_default.aspx?id=" + id, true);
                xhttp1.send();
        }
        else {
            $("#class-list-option-btn").addClass("w3-hide");
            $("#class-report").css("display", "none");
        }
        
    });
    $(".btn_add_student").on("click", function () {
        $('#themhocvien').fadeIn();
    });
    $(".add-btn").on("click", function () {
        this.parentElement.parentElement.getElementsByClassName("add_student_select")[0].innerHTML = 1;
    });
    $(".cancel-checked").on("click", function () {
        this.parentElement.parentElement.getElementsByClassName("add_student_select")[0].innerHTML = 0;
    });
    $('#agree_add_student').click(function () {
        var cls = document.getElementById("ddl_class").value;
        var check = "";
        var select = document.getElementsByClassName("add_student_select");
        var id = document.getElementsByClassName("add_student_id");
        for(var i=0;i<id.length;i++)
        {
            check += id[i].innerHTML + "_" + select[i].innerHTML + ",";
        }
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    location.reload(true);
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/add_student.aspx?check=" + check + "&cls="+cls, true);
        xhttp.send();
    });
    /*Nhập điểm*/
    $(".btn_insert_point").click(function () {
        $("#nhapdiem").fadeIn();
    });
    $(".create-insert-point-btn").click(function () {
        $(".class-insert-point-header").css("padding", "10px 0");
        $(".class-insert-point-header-text").css("font-size", "18px");
        $(".class-insert-point-header-text").css("padding", "4px");
        $(".class-insert-point-header-drop").addClass("dropped");
        $(".class-insert-point-header-drop").animate({ "height": "toggle" }, "fast");
        $("#class-insert-point-table").animate({ "height": "toggle" }, "fast").removeClass("w3-hide");
        var id = document.getElementById("ddl_exam").value;
        get_score_exam(id);
        $("#class-insert-point-option").animate({ "height": "toggle" }, "fast").removeClass("w3-hide");

    })
    $(".close-insert-point-btn").click(function () {
        $(".class-insert-point-header").css("padding", "40px 5px 52px 5px");
        $(".class-insert-point-header-text").css("font-size", "30px");
        $(".class-insert-point-header-text").css("padding", "8px 0");
        if ($(".class-insert-point-header-drop").hasClass("dropped")) {
            $(".class-insert-point-header-drop").removeClass("dropped");
            $(".class-insert-point-header-drop").animate({ "height": "toggle" }, "fast");
        }
        else {
        }
        $("#class-insert-point-table").addClass("w3-hide");
        $("#class-insert-point-option").addClass("w3-hide");
        $("#nhapdiem").fadeOut();
    })
    $(".cancel-insert-point-btn").click(function () {
        $(".class-insert-point-header").css("padding", "40px 5px 52px 5px");
        $(".class-insert-point-header-text").css("font-size", "30px");
        $(".class-insert-point-header-text").css("padding", "8px 0");
        $(".class-insert-point-header-drop").removeClass("dropped");
        $(".class-insert-point-header-drop").animate({ "height": "toggle" }, "fast");
        $("#class-insert-point-table").animate({ "height": "toggle" }, "fast");
        $("#class-insert-point-option").animate({ "height": "toggle" }, "fast");
    })
    $("#class-point-slide").carousel({ interval: false });
    /**/
    function showcheck() {
        var cls = document.getElementById("ddl_class").value;
        var date = document.getElementById("check_date").value;
        var shift = document.getElementById("check_shifts").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    $('#diemdanh').fadeIn();
                    document.getElementById('check-in-list').innerHTML = xhttp.responseText;
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/show_check.aspx?cls=" + cls + "&date=" + date + "&shift=" + shift, true);
        xhttp.send();
    }
    $(".btn_check").on("click", function () {
        showcheck();
    });
    $("#btn_show_check").on("click", function () {
        showcheck();
    });
    $('#cancel_add_student').click(function () {
        var studentchecked = document.getElementsByClassName('student-checked');
        var cancelchecked = document.getElementsByClassName('cancel-checked');
        var addbtn = document.getElementsByClassName('add-btn');
        var reset = document.getElementsByClassName("add_student_select");
        for (var i = 0; i < studentchecked.length; i++) {
            studentchecked[i].style.display = 'none';
        }
        for (var j = 0; j < addbtn.length; j++) {
            addbtn[j].style.display = 'inline-block';
        }
        for (var k = 0; k < cancelchecked.length; k++) {
            cancelchecked[k].style.display = 'none';
        }
        for (var i = 0; i < reset.length; i++) {
            reset[i].innerHTML = 0;
        }
        $("#themhocvien").fadeOut();
    });
    $(".btn_check_student").on("click", function () {
        var cls = document.getElementById("ddl_class").value;
        var student = document.getElementsByClassName("check_in_student");
        var date = document.getElementById("check_date").value;
        var shift = document.getElementById("check_shifts").value;
        var check = "";
        for (var i = 0; i < student.length; i++) {
            var id = document.getElementsByClassName("check_student_id")[i].innerHTML;
            var status = "4";
            if ($('#dunggio'+id).is(":checked"))
                status = "1";
            else
                if ($('#ditre'+id).is(":checked"))
                    status = "2";
                else
                    if ($('#vangcophep'+id).is(":checked"))
                        status = "3";
            check += document.getElementsByClassName("check_student_id")[i].innerHTML;
            check += "_"
            check += status;
            check += ",";
        }
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    location.reload(true);
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/check_in_user.aspx?cls=" + cls + "&check="+check + "&date="+date+"&shift="+shift, true);
        xhttp.send();
    });
    $('#cancel_check_in').click(function () {
        $("#diemdanh").fadeOut();
    });
    $(".btn_change_class").on("click", function () {
        var class_id = document.getElementById("ddl_change_class").value;
        var std_id = document.getElementById("student_id").innerHTML;

        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    location.reload(true);
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/change_class.aspx?class_id=" + class_id + "&std_id=" + std_id, true);
        xhttp.send();
    });
    $(".btn_remove_student").on("click", function () {
        var std_id = document.getElementById("remove_student_id").innerHTML;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    location.reload(true);
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/remove_student.aspx?std_id=" + std_id, true);
        xhttp.send();
    });
    $("#class-report-option").on("change", function () {
        var valiu = $(this).val();
        if (valiu == 1) {
            var ctx1 = document.getElementById("canvas1").getContext("2d");
            window.myLine = new Chart(ctx1, config1);
            $("#class-report-date").css("display", "inline-block");
            $("#class-report-year").css("display", "none");
            $("#canvas1").css("display", "block");
            $("#canvas2").css("display", "none");
            $("#canvas3").css("display", "none");
        }
        else if (valiu == 2) {
            $("#class-report-date").css("display", "none");
            $("#class-report-year").css("display", "none");
            var ctx2 = document.getElementById("canvas2").getContext("2d");
            window.myLine = new Chart(ctx2, config2);
            $("#canvas1").css("display", "none");
            $("#canvas2").css("display", "block");
            $("#canvas3").css("display", "none");
        }
        else {
            $("#class-report-date").css("display", "none");
            $("#class-report-year").css("display", "inline-block");
            var ctx3 = document.getElementById("canvas3").getContext("2d");
            window.myLine = new Chart(ctx3, config3);
            $("#canvas1").css("display", "none");
            $("#canvas2").css("display", "none");
            $("#canvas3").css("display", "block");
        }
    });
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////  Class _ Manager ////////////////////////////////////////////////////////
    $("#find_class").on("keyup", function () {
        var str = document.getElementById("find_class").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    document.getElementById("class_show").innerHTML = xhttp.responseText;
                    $(".class-options").click(function () {
                        var id = this.getElementsByClassName("class_id")[0].innerHTML;

                        var xhttp;
                        xhttp = new XMLHttpRequest();
                        xhttp.onreadystatechange = function () {
                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                $(document).ready(function () {
                                    document.getElementById('sualop').innerHTML = xhttp.responseText;
                                    document.getElementById('sualop').style.display = 'block';
                                    $(document).ready(function () {
                                        $(".active_class").click(function () {
                                            if ($(this).hasClass("off")) {
                                                $(this).removeClass("off");
                                                $(this).removeClass("fa-rotate-180");
                                                $(this).removeClass("w3-text-red");
                                                $(this).addClass("w3-text-white");
                                            }
                                            else {
                                                $(this).addClass("w3-text-red");
                                                $(this).removeClass("w3-text-white");
                                                $(this).addClass("fa-rotate-180");
                                                $(this).addClass("off");
                                            }
                                        });
                                        $(".btn_edited_class").on("click", function () {
                                            var cls = document.getElementById("edit_class_id").value;
                                            var name = document.getElementById("edit_class_name").value;
                                            var teacher = document.getElementById("ddl_edit_teacher").value;
                                            var open = document.getElementById("edit_open_date").value;
                                            var close = document.getElementById("edit_close_date").value;
                                            var type = document.getElementById("edit_class_type").value;

                                            var schedule = "";
                                            if ($('#edit_monday').is(":checked"))
                                                schedule += "1,";
                                            if ($('#edit_tuesday').is(":checked"))
                                                schedule += "2,";
                                            if ($('#edit_wednesday').is(":checked"))
                                                schedule += "3,";
                                            if ($('#edit_thursday').is(":checked"))
                                                schedule += "4,";
                                            if ($('#edit_friday').is(":checked"))
                                                schedule += "5,";
                                            if ($('#edit_saturday').is(":checked"))
                                                schedule += "6,";

                                            if (schedule == "")
                                                schedule = ",";
                                            var morning = "", afternoon = "", evening = "";

                                            if (document.getElementById("edit_morning_from").value != "")
                                                morning = document.getElementById("edit_morning_from").value + "_" + document.getElementById("edit_morning_to").value;
                                            if (document.getElementById("edit_afternoon_from").value != "")
                                                afternoon = document.getElementById("edit_afternoon_from").value + "_" + document.getElementById("edit_afternoon_to").value;
                                            if (document.getElementById("edit_evening_from").value != "")
                                                evening = document.getElementById("edit_evening_from").value + "_" + document.getElementById("edit_evening_to").value;

                                            var time_study = morning + "," + afternoon + "," + evening + ",";

                                            var lesson = $("#txta_edit_lession").val();
                                            var level = document.getElementById("edit_degree").value;
                                            var active = "1";
                                            if ($(".active_class").hasClass("off"))
                                                active = "0";
                                            if (name.trim() == "")
                                                alert("Tên lớp không được để trống!");
                                            else {
                                                if (open == "")
                                                    alert("Ngày khai giảng không được để trống!");
                                                else {
                                                    if (close == "")
                                                        alert("Ngày tốt nghiệm không được để trống");
                                                    else {
                                                        var xhttp;
                                                        xhttp = new XMLHttpRequest();
                                                        xhttp.onreadystatechange = function () {
                                                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                                                $(document).ready(function () {
                                                                    location.reload(true);
                                                                });
                                                            }
                                                        };
                                                        xhttp.open("GET", "../ajax/asp/class/edited_class.aspx?cls=" + cls + "&name=" + name.trim() + "&teacher=" + teacher + "&open=" + open + "&close=" + close + "&type=" + type.trim() + "&schedule=" + schedule + "&time_study=" + time_study + "&lesson=" + lesson.trim() + "&level=" + level.trim() + "&active=" + active, true);
                                                        xhttp.send();
                                                    }
                                                }
                                            }
                                        });
                                    });

                                });
                            }
                        };
                        xhttp.open("GET", "../ajax/asp/class/edit_class_model.aspx?id=" + id, true);
                        xhttp.send();
                    });
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/find_class.aspx?str=" + str, true);
        xhttp.send();
    });
    $(".btn_merge_class").on("click", function () {
        var from = document.getElementById("merge_class_from").value;
        var to = document.getElementById("merge_class_to").value;
        if (from == to) {
            document.getElementById("merge_class").style.display = "none";
            document.getElementById("nhaplop").style.display = "none";
            alert("Hai lớp muốn nhập phải khác nhau!");
        } else {
            var xhttp;
            xhttp = new XMLHttpRequest();
            xhttp.onreadystatechange = function () {
                if (xhttp.readyState == 4 && xhttp.status == 200) {
                    $(document).ready(function () {
                        location.reload(true);
                    });
                }
            };
            xhttp.open("GET", "../ajax/asp/class/merge_class.aspx?from=" + from+"&to="+to, true);
            xhttp.send();
        }
    });
    $(".class-options").click(function () {
        var id = this.getElementsByClassName("class_id")[0].innerHTML;
        
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                $(document).ready(function () {
                    document.getElementById('sualop').innerHTML = xhttp.responseText;
                    document.getElementById('sualop').style.display = 'block';
                    $(document).ready(function () {
                        $(".active_class").click(function () {
                            if ($(this).hasClass("off")) {
                                $(this).removeClass("off");
                                $(this).removeClass("fa-rotate-180");
                                $(this).removeClass("w3-text-red");
                                $(this).addClass("w3-text-white");
                            }
                            else {
                                $(this).addClass("w3-text-red");
                                $(this).removeClass("w3-text-white");
                                $(this).addClass("fa-rotate-180");
                                $(this).addClass("off");
                            }
                        });
                        $(".btn_edited_class").on("click", function () {
                            var cls = document.getElementById("edit_class_id").value;
                            var name = document.getElementById("edit_class_name").value;
                            var teacher = document.getElementById("ddl_edit_teacher").value;
                            var open = document.getElementById("edit_open_date").value;
                            var close = document.getElementById("edit_close_date").value;
                            var type = document.getElementById("edit_class_type").value;
                            
                            var schedule = "";
                            if ($('#edit_monday').is(":checked"))
                                schedule += "1,";
                            if ($('#edit_tuesday').is(":checked"))
                                schedule += "2,";
                            if ($('#edit_wednesday').is(":checked"))
                                schedule += "3,";
                            if ($('#edit_thursday').is(":checked"))
                                schedule += "4,";
                            if ($('#edit_friday').is(":checked"))
                                schedule += "5,";
                            if ($('#edit_saturday').is(":checked"))
                                schedule += "6,";

                            if (schedule == "")
                                schedule = ",";
                            var morning = "", afternoon = "", evening = "";

                            if (document.getElementById("edit_morning_from").value != "")
                                morning = document.getElementById("edit_morning_from").value + "_" + document.getElementById("edit_morning_to").value;
                            if (document.getElementById("edit_afternoon_from").value != "")
                                afternoon = document.getElementById("edit_afternoon_from").value + "_" + document.getElementById("edit_afternoon_to").value;
                            if (document.getElementById("edit_evening_from").value != "")
                                evening = document.getElementById("edit_evening_from").value + "_" + document.getElementById("edit_evening_to").value;

                            var time_study = morning + "," + afternoon + "," + evening+",";

                            var lesson = $("#txta_edit_lession").val();
                            var level = document.getElementById("edit_degree").value;
                            var active = "1";
                            if ($(".active_class").hasClass("off"))
                                active = "0";
                            if (name.trim() == "")
                                alert("Tên lớp không được để trống!");
                            else {
                                if (open == "")
                                    alert("Ngày khai giảng không được để trống!");
                                else {
                                    if (close == "")
                                        alert("Ngày tốt nghiệm không được để trống");
                                    else {
                                        var xhttp;
                                        xhttp = new XMLHttpRequest();
                                        xhttp.onreadystatechange = function () {
                                            if (xhttp.readyState == 4 && xhttp.status == 200) {
                                                $(document).ready(function () {
                                                    location.reload(true);
                                                });
                                            }
                                        };
                                        xhttp.open("GET", "../ajax/asp/class/edited_class.aspx?cls=" + cls + "&name=" + name.trim() + "&teacher=" + teacher + "&open=" + open + "&close=" + close + "&type=" + type.trim() + "&schedule=" + schedule + "&time_study=" + time_study + "&lesson=" + lesson.trim() + "&level=" + level.trim()+"&active="+active, true);
                                        xhttp.send();
                                    }
                                }
                            }
                        });
                    });
                    
                });
            }
        };
        xhttp.open("GET", "../ajax/asp/class/edit_class_model.aspx?id=" + id, true);
        xhttp.send();
    });
    $(".btn_add_class").on("click", function () {
        var name = document.getElementById("add_class_name").value;
        var teacher = document.getElementById("add_class_teacher").value;
        var open = document.getElementById("add_class_open").value;
        var close = document.getElementById("add_class_close").value;
        var type = document.getElementById("add_class_type").value;
        var schedule = "";
        if ($('#monday').is(":checked"))
            schedule += "1,";
        if ($('#tuesday').is(":checked"))
            schedule += "2,";
        if ($('#wednesday').is(":checked"))
            schedule += "3,";
        if ($('#thursday').is(":checked"))
            schedule += "4,";
        if ($('#friday').is(":checked"))
            schedule += "5,";
        if ($('#saturday').is(":checked"))
            schedule += "6,";

        if (schedule == "")
            schedule = ",";
        var morning = "", afternoon = "", evening = "";

        if (document.getElementById("add_morning_from").value != "")
            morning = document.getElementById("add_morning_from").value + "_" + document.getElementById("add_morning_to").value;
        if (document.getElementById("add_afternoon_from").value != "")
            afternoon = document.getElementById("add_afternoon_from").value + "_" + document.getElementById("add_afternoon_to").value;
        if (document.getElementById("add_evening_from").value != "")
            evening = document.getElementById("add_evening_from").value + "_" + document.getElementById("add_evening_to").value;
        var time_study = morning + "," + afternoon + "," + evening + ",";

        var lesson = $("#add_class_lesson").val();
        var level = document.getElementById("add_class_level").value;
        if (name.trim() == "")
            alert("Tên lớp không được để trống!");
        else {
            if (open == "")
                alert("Ngày khai giảng không được để trống!");
            else {
                if (close == "")
                    alert("Ngày tốt nghiệm không được để trống");
                else {
                    //alert("name=" + name.trim() + "&teacher=" + teacher + "&open=" + open + "&close=" + close + "&type=" + type.trim() + "&schedule=" + schedule + "&time_study=" + time_study + "&lesson=" + lesson.trim() + "&level=" + level.trim());
                    var xhttp;
                    xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function () {
                        if (xhttp.readyState == 4 && xhttp.status == 200) {
                            $(document).ready(function () {
                                location.reload(true);
                            });
                        }
                    };
                    xhttp.open("GET", "../ajax/asp/class/add_class.aspx?name=" + name.trim() + "&teacher=" + teacher + "&open=" + open + "&close=" + close + "&type=" + type.trim() + "&schedule=" + schedule + "&time_study=" + time_study + "&lesson=" + lesson.trim() + "&level=" + level.trim(), true);
                    xhttp.send();
                }
            }
        }
    });

    $("#ddl_exam_semester").on("change", function () {
        var semester = document.getElementById("ddl_exam_semester").value;
        if (semester == 0) {
            $("#ddl_exam_group").addClass("w3-hide");
            $("#ddl_exam").addClass("w3-hide");
            $("#btn_add_score").addClass("w3-hide");
        }
        else {
            $("#ddl_exam_group").removeClass("w3-hide");
            $("#ddl_exam").removeClass("w3-hide");
            $("#btn_add_score").removeClass("w3-hide");

            get_group(semester);
            
        }
    });
    $("#ddl_exam_group").on("change", function () {
        var group = document.getElementById("ddl_exam_group").value;
        get_exam(group);
        
    });
    function get_group(id) {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("ddl_exam_group").innerHTML = xhttp.responseText;
                var group = document.getElementById("ddl_exam_group").value;
                get_exam(group);
            }
        };
        xhttp.open("GET", "../ajax/asp/class/get_exam_group.aspx?id=" + id, true);
        xhttp.send();
    }

    function get_exam(id) {
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("ddl_exam").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/class/get_exam.aspx?id="+id, true);
        xhttp.send();
    }

    function get_score_exam(id) {
        var cls = document.getElementById("ddl_class").value;
        var xhttp;
        xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                document.getElementById("class-insert-point-table").innerHTML = xhttp.responseText;
            }
        };
        xhttp.open("GET", "../ajax/asp/class/add_score_form.aspx?id=" + id +"&cls="+cls, true);
        xhttp.send();
    }
});
function save_score() {
    var lesson = document.getElementById("ddl_exam").value;
    var student_length = document.getElementsByClassName("student").length;
    var score = "";
    if (student_length != 0) {
        for (var i = 0; i < student_length; i++) {
            score += document.getElementsByClassName("student")[i].getElementsByClassName("student_id")[0].innerHTML;
            
            for (var j = 0; j < document.getElementsByClassName("student")[i].getElementsByClassName("score").length; j++)
            {
                score += "_";
                score += document.getElementsByClassName("student")[i].getElementsByClassName("score")[j].value;
            }
            score += ";";
        }
        try {
            $.post("../ajax/asp/class/add_score.aspx", { 'score': score, 'lesson': lesson });
            document.getElementById("success_content").innerHTML = "Điểm đã được lưu thành công";
            document.getElementById("success-modal").style.display = "block";
            setTimeout('$("#success-modal").fadeOut()', 3000);
        }
        catch (e) {
            document.getElementById("error_content").innerHTML = e.message;
            document.getElementById("error-modal").style.display = "block";
            setTimeout('$("#error-modal").fadeOut()', 3000);
        }
    }else
    {
        document.getElementById("error_content").innerHTML = "Không có học viên nào trong lớp học này!";
        document.getElementById("error-modal").style.display = "block";
        setTimeout('$("#error-modal").fadeOut()', 3000);
    }
}
function change_report_score()
{
    var id = document.getElementById("ddl_class").value;
    var group = document.getElementById("ddl_report_group").value;
    document.getElementsByClassName("class-insert-point-table")[0].innerHTML = '<div id="loading"><div id="loading-center-absolute"><div class="object w3-text-teal" id="object_four"></div><div class="object w3-text-teal" id="object_three"></div><div class="object w3-text-teal" id="object_two"></div><div class="object w3-text-teal" id="object_one"></div></div></div>';

    var xhttp;
    xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            document.getElementsByClassName("class-insert-point-table")[0].innerHTML = xhttp.responseText;
        }
    };
    xhttp.open("GET", "../ajax/asp/class/report_score_request.aspx?id=" + id + "&group="+group, true);
    xhttp.send();
}